#include <iostream>
#include <vector>
using namespace std;
//这次写的太仓促了,下次遇到模拟遍历题一定要先画图想清楚了再写...
class Solution
{
public:
    bool check_line(vector<vector<char>> &board, int rMove, int cMove, char color)
    {
        // up
        bool up = false;
        bool flag = true;
        if (rMove >= 2 && board[rMove - 1][cMove] != color && board[rMove - 1][cMove] != '.')
        {
            int i;
            for (i = rMove - 1; i >= 0 && board[i][cMove] != color; i--)
            {
                if (board[i][cMove] == '.')
                {
                    flag = false;
                    break;
                }
            }
            if (i >= 0 && flag)
                up = true;
        }
        // down
        bool down = false;
        flag = true;
        if (rMove <= 5 && board[rMove + 1][cMove] != color && board[rMove + 1][cMove] != '.')
        {
            int i;
            for (i = rMove + 1; i <= 7 && board[i][cMove] != color; i++)
                if (board[i][cMove] == '.')
                {
                    down = false;
                    flag = false;
                    break;
                }
            if (i <= 7 && flag)
                down = true;
        }
        // left
        bool left = false;
        flag = true;
        if (cMove >= 2 && board[rMove][cMove - 1] != color && board[rMove][cMove - 1] != '.')
        {
            int j;
            for (j = cMove - 1; j >= 0 && board[rMove][j] != color; j--)
                if (board[rMove][j] == '.')
                {
                    flag = false;
                    break;
                }
            if (j >= 0 && flag)
                left = true;
        }
        // right
        bool right = false;
        flag = true;
        if (cMove <= 5 && board[rMove][cMove + 1] != color && board[rMove][cMove + 1] != '.')
        {
            int j;
            for (j = cMove + 1; j <= 7 && board[rMove][j] != color; j++)
                if (board[rMove][j] == '.')
                {
                    flag = false;
                    break;
                }
            cout << j << flag << endl;
            if (j <= 7 && flag)
                right = true;
        }
        cout << up << down << left << right << endl;
        return up || down || left || right;
    }
    bool check_diagonal(vector<vector<char>> &board, int rMove, int cMove, char color)
    {
        // left up
        bool l_up = false;
        bool flag = true;
        if (rMove >= 2 && cMove >= 2)
        {
            int i = rMove - 1, j = cMove - 1;
            if (board[i][j] != color && board[i][j] != '.')
            {
                for (; i >= 0 && j >= 0 && board[i][j] != color; i--, j--)
                    if (board[i][j] == '.')
                    {
                        flag = false;
                        break;
                    }
                if (flag && i >= 0 && j >= 0)
                    l_up = true;
            }
        }
        // right up
        bool r_up = false;
        flag = true;
        if (rMove >= 2 && cMove <= 5)
        {
            int i = rMove - 1, j = cMove + 1;
            if (board[i][j] != color && board[i][j] != '.')
            {
                for (; i >= 0 && j <= 7 && board[i][j] != color; i--, j++)
                    if (board[i][j] == '.')
                    {
                        flag = false;
                        break;
                    }
                if (flag && i >= 0 && j <= 7)
                    r_up = true;
            }
        }
        // left down
        bool l_down = false;
        flag = true;
        if (rMove <= 5 && cMove >= 2)
        {
            int i = rMove + 1, j = cMove - 1;
            if (board[i][j] != color && board[i][j] != '.')
            {

                for (; i <= 7 && j >= 0 && board[i][j] != color; i++, j--)
                    if (board[i][j] == '.')
                    {
                        flag = false;
                        break;
                    }
                if (flag && i <= 7 && j >= 0)
                    l_down = true;
            }
        }
        // right down
        bool r_down = false;
        flag = true;
        if (rMove <= 5 && cMove <= 5)
        {
            int i = rMove + 1, j = cMove + 1;
            if (board[i][j] != color && board[i][j] != '.')
            {
                for (; i <= 7 && j <= 7 && board[i][j] != color; i++, j++)
                {
                    if (board[i][j] == '.')
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag && i <= 7 && j <= 7)
                    r_down = true;
            }
        }
        cout << l_up << l_down << r_up << r_down << endl;
        return l_up || l_down || r_up || r_down;
    }
    bool checkMove(vector<vector<char>> &board, int rMove, int cMove, char color)
    {
        return check_line(board, rMove, cMove, color) || check_diagonal(board, rMove, cMove, color);
    }
};